﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FlexControls
{
    public partial class FlexButtons : UserControl
    {
        public event EventHandler Click;
        
        public int ClickState = clsFlex.CLICK_THEMMOI;
        protected virtual void OnClick()
        {
            if (this.Click != null)
            {
                this.Click(this, EventArgs.Empty);

            }
        }
        public FlexButtons()
        {
            InitializeComponent();
            this.Size = new Size(462, 92);
        }
        private bool booPrint = false;
        public bool fcPrint
        {
            get
            {
                return booPrint;
            }
            set
            {
                booPrint = value;
                if (booPrint == true)
                {
                    butIn.Visible = true;
                }
                else
                    butIn.Visible = false;
            }
        }

        private void butIn_Click(object sender, EventArgs e)
        {
            ClickState = clsFlex.CLICK_IN;
            OnClick();
        }

        private void butThem_Click(object sender, EventArgs e)
        {
            if (ClickState == clsFlex.CLICK_CAPNHAT)
            {
                ClickState = clsFlex.CLICK_THEMMOI;
                butThem.Text = "Lưu";
            }
            else
            ClickState = clsFlex.CLICK_LUU;
            butXoa.Enabled = false;
            butCapNhat.Enabled = false;
            OnClick();
        }

        private void butCapNhat_Click(object sender, EventArgs e)
        {
            ClickState = clsFlex.CLICK_CAPNHAT;
            butXoa.Enabled = false;
            butCapNhat.Enabled = false;
            OnClick();
        }

        private void butXoa_Click(object sender, EventArgs e)
        {
            ClickState = clsFlex.CLICK_XOA;
            butXoa.Enabled = false;
            butCapNhat.Enabled = false;
            OnClick();
        }

        private void butThoat_Click(object sender, EventArgs e)
        {
            ClickState = clsFlex.CLICK_THOAT;
            OnClick();
        }

        public void ChangeState(int intState)
        {
            try
            {
                switch (intState)
                {
                    case clsFlex.CLICK_LUU:
                        butCapNhat.Enabled = false;
                        butXoa.Enabled = false;
                        butThem.Enabled = true;
                        butThem.Text = "Lưu";
                        break;
                    case clsFlex.CLICK_CAPNHAT:
                        ClickState = clsFlex.CLICK_CAPNHAT;
                        butThem.Enabled = true;
                        butXoa.Enabled = true;
                        butCapNhat.Enabled = true;
                        butThem.Text = "Thêm mới";
                        break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Button Change State... \n\nChi tiết:\n" + ex, "Thông báo lỗi");
            }
        }
    }
}
